package com.docMan.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;

import com.docMan.utils.FinalConfig;

public class PageLucene {
	private int totalCount = 0;
	private int everyPage = 10;
	private int currentPage = 1;
	private int beginIndex = 0;
	private boolean hasNextPage;
	private boolean hasPrePage;
	private int totalPageCount = 0;
	// 搜索的文本内容
	private String searchText;
	private Date startDate;
	private Date endDate;
	// 搜索范围,全部，OA，或者只有本系统
	private String indexFrom;
	// 搜索类型，全文搜索或者标题搜索或者文号搜索 全文搜索为0 标题搜索为1
	private String searchType;
	// 文号
	private String wh;
	private String lwdw;
	private boolean iswhSearch = false;
	private boolean islwdwSearch = false;
	private boolean isPage = false;
	private boolean orderByTime = false;
	private List<IndexFile> results = new ArrayList<IndexFile>();
	private boolean MutilLwdw=false;
	private static String[] lwdws={"宁波市人民政府","市委","市政府承办单"};
	public PageLucene(int totalCount, int everyPage, int currentPage,
			int beginIndex) {
		super();
		this.totalCount = totalCount;
		this.everyPage = everyPage;
		this.currentPage = currentPage;
		this.beginIndex = beginIndex;
	}

	public PageLucene() {
	}

	/**
	 * @return the isMutilLwdw
	 */
	public boolean getMutilLwdw() {
		return MutilLwdw;
	}

	/**
	 * @param isMutilLwdw the isMutilLwdw to set
	 */
	public void setMutilLwdw(boolean isMutilLwdw) {
		this.MutilLwdw = isMutilLwdw;
	}

	/**
	 * @return the lwdws
	 */
	public static String[] getLwdws() {
		return lwdws;
	}

	/**
	 * @param lwdws the lwdws to set
	 */
	public static void setLwdws(String[] lwdws) {
		PageLucene.lwdws = lwdws;
	}

	public boolean getOrderByTime() {
		if (searchText == null || !searchText.trim().equals("")) {
			return false;
		}
		return orderByTime;
	}

	public void setOrderByTime(boolean orderByTime) {
		this.orderByTime = orderByTime;
	}

	public void setLwdw(String lwdw) {
		this.lwdw = lwdw;
	}

	public String getLwdw() {
		return lwdw;
	}

	public boolean getIsPage() {
		return isPage;
	}

	public void setIsPage(boolean isPage) {
		this.isPage = isPage;
	}

	public boolean getIswhSearch() {
		return iswhSearch;
	}

	public void setIswhSearch(boolean iswhSearch) {
		this.iswhSearch = iswhSearch;
	}

	public boolean getIslwdwSearch() {
		return islwdwSearch;
	}

	public void setIslwdwSearch(boolean islwdwSearch) {
		this.islwdwSearch = islwdwSearch;
	}

	public String getWh() {
		return wh;
	}

	public void setWh(String wh) {
		this.wh = wh;
	}

	public String getSearchType() {
		return searchType;
	}

	public void setSearchType(String searchType) {
		this.searchType = searchType;
	}

	public String getIndexFrom() {
		return indexFrom;
	}

	public void setIndexFrom(String indexFrom) {
		this.indexFrom = indexFrom;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public int getTotalPageCount() {
		return totalPageCount;
	}

	public void setTotalPageCount(int totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	public List<IndexFile> getResults() {
		return results;
	}

	public void setResults(List<IndexFile> results) {
		this.results = results;
	}

	public String getSearchText() {

		return searchText;
	}

	public void setSearchText(String searchText) {
		this.searchText = searchText.replace("[", " ").replace("]", " ")
				.replace("〔", " ").replace("〕", " ");
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getEveryPage() {
		return everyPage;
	}

	public void setEveryPage(int everyPage) {
		this.everyPage = everyPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getBeginIndex() {
		return beginIndex;
	}

	public void setBeginIndex(int beginIndex) {
		this.beginIndex = beginIndex;
	}

	public boolean isHasNextPage() {
		return hasNextPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

	public boolean isHasPrePage() {
		return hasPrePage;
	}

	public void setHasPrePage(boolean hasPrePage) {
		this.hasPrePage = hasPrePage;
	}

	/**
	 * 设置完totalCount 后对page 进行计算初始化 计算pagecount 和是否还有下一页或上一页
	 */
	public void initPageLucene() {
		if (totalCount % everyPage == 0) {
			totalPageCount = totalCount / everyPage;
		} else {
			totalPageCount = totalCount / everyPage + 1;
		}
		setTotalPageCount(totalPageCount);
		setHasPrePage(currentPage == 1 ? false : true);
		setHasNextPage(currentPage == getTotalPageCount()
				|| this.totalPageCount == 0 ? false : true);
		setBeginIndex(getCurrentPage() * getEveryPage());
	}

	public boolean isBooleanQuery() {
		if (null == startDate || null == endDate) {
			return false;
		}
		return true;
	}

	public void init() {
		if (null == wh) {

		}
	}

	/**
	 * 根据pageLucene的搜索类型获取搜索的字段 如果为标题的则搜索字段只有fileName 全文搜索为 fileName 加content
	 * 如果有lwdw搜索字段有lwdw字段，其他同上 如果有问好搜索的话，则有wh字段，其他同上
	 * 
	 * @return
	 */
	public String[] getFileSearchFields() {
		String[] fields;
		if (searchType.equals(FinalConfig.searchType_all)) {
//			fields = new String[] { "fileName", "content", "lwbh", "swbh" };
			fields=new String[] { "content", "lwbh" };
		} else if (searchType.equals(FinalConfig.searchType_title)) {
			fields = new String[] { "fileName" };
		} else {
//			fields = new String[] { "swbh", "lwbh" };
			fields = new String[] { "lwbh" };
		}
		return fields;
	}
}
